#include<bits/stdc++.h>

#define rp(i,a,b) for(int i=a;i<b;++i)
#define rrp(i,b,a) for(int i=b;i>=a;--i)

using namespace std;

int a[310000] = {0};

int main(){
	int n,k;scanf("%d%d", &n,&k);
	long long ans = 0;
	rp(i , 0 , n){
		int tmp;
		scanf("%d", &tmp);
		++a[tmp];
	}
	int numofbox = 0;
	while(a[0]>0&&numofbox<k){
		// printf("a[0] = %d\n", a[0]);
		a[0] -= 1;
		int cnt = 1;
		while(a[cnt]){
			a[cnt] -= 1;
			++cnt;
		}
		// printf("cnt = %d\n", cnt);
		ans += cnt;
		numofbox++;
	}
	printf("%lld\n", ans);
	
	return 0;
}